﻿using System;
using System.ComponentModel.DataAnnotations;
using AllIsWell.Core.Models;
using AllIsWell.Tests.TestData;
using NUnit.Framework;

namespace AllIsWell.Core.Tests.Models
{
    [TestFixture]
    class PageTests : ModelTests
    {
        private Page _page;

        [SetUp]
        public void SetUp()
        {
            _page = new Page { DateTime = DateTime.Today, Destiny = DestinySeed.GetDestiny(1) };
        }

        [Test]
        [ExpectedException(typeof(ValidationException), ExpectedMessage = "Date is requried")]
        public void DateTimeIsRequired()
        {
            _page.DateTime = new DateTime();

            ValidateModel(_page);
        }

        [Test]
        [ExpectedException(typeof(ValidationException), ExpectedMessage = "DateTime should not be a past/future date")]
        public void DateTimeShouldNotBePastDate()
        {
            _page.DateTime = GetYesterday();
            
            ValidateModel(_page);
        }

        private DateTime GetYesterday()
        {
            return DateTime.Today.Subtract(new TimeSpan(1, 0, 0, 0));
        }

        [Test]
        [ExpectedException(typeof(ValidationException), ExpectedMessage = "DateTime should not be a past/future date")]
        public void DateTimeShouldNotBeFutureDate()
        {
            _page.DateTime = GetTomorrow();
            
            ValidateModel(_page);
        }

        private DateTime GetTomorrow()
        {
            return DateTime.Today.Add(new TimeSpan(1, 0, 0, 0));
        }

        [Test]
        public void DateTimeShouldBeToday()
        {
            ValidateModel(_page);

            Assert.IsNotNull(_page);
        }

        [Test]
        [ExpectedException(typeof(ValidationException), ExpectedMessage = "Destiny is required")]
        public void DestinyIsRequired()
        {
            _page.Destiny = null;

            ValidateModel(_page);
        }
    }
}